<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/8/28
 * Time: 11:10
 */
if(!session_id()) session_start();
header("Access-Control-Allow-Origin:*");
header('Access-Control-Allow-Methods:POST,GET');
header('Access-Control-Allow-Headers:x-requested-with,content-type');
require_once ('dbServerConnect.php');
$con = new DB();
$link = $con->mySqlServer();
if(!$link) {
    echo "mysql connect fail";
    return;
}


$json_raw = file_get_contents("php://input");
//    print_r(apache_response_headers());
$json_array = json_decode($json_raw,true);
$username = $json_array['username'];
$password = $json_array['password'];
//$password = md5($password);


$sql = "select username,password from login where username='$username' and password='$password'";

$result = mysqli_query($link,$sql) or  die(mysqli_error($link));

$row = mysqli_fetch_row($result);

if($row) {
    $res = array('result' => array('token' => md5($password), 'status' => 1,'mgs'=>'登录成功！'));
	$_SESSION["username"] = $username;
    echo json_encode($res);
}
else {
    $res = array('result' => array('notice' => '兄弟，你输入的密码不对哦！', 'status' => 0,'mgs'=>'登录失败！'));
    echo json_encode($res);
}